import Client from './Client_nodefetch.mjs';
// import { LocalStorage } from 'node-localstorage';

let data = {};
// data.username="mahongquan"
// data.password="mhq730208[]"
data.username = "gte"
data.password = "hx123456."
// data.type="2"
// data.captcha=""
// data.checkKey="1686279246495"
let login_res = null;
const getMethod = () => {
    console.log("getMethod")
    Client.post("http://10.0.108.4:9999/oapi/template/getTemplateBindMethods", data, (data) => {
        // setState((state)=>({...state,login_data:data}))
        console.log("ok");
        console.log(data);
    }, (e) => {
        console.log("error");
        console.log(e);
    })
}
const getModuleTree0 = () => {
    let token = login_res.data.token;
    let url = new URL('http://10.0.108.4:3000/hanson-lcdp/module/getAllModuleTreeUseByRoleIds');
    
    url.searchParams.append('_t', Math.floor(Date.now() / 1000));
    url.searchParams.append('projectId', 'n7hnngimnxalqi2ih8euj59z3upscog1');
    
    Client.get(url.toString(), null, {
        headers: {
            'Content-Type': 'application/json',
            'x-access-token': token
        }
    }, (data) => {
        console.log("ok");
        console.log(data);
    }, (e) => {
        console.log("error");
        console.log(e);
    });
};
const getModuleTree = () => {
    const token = login_res.data.token;
    const url = new URL('http://10.0.108.4:3000/hanson-lcdp/module/getAllModuleTreeUseByRoleIds');

    // 添加查询参数
    url.searchParams.append('_t', Date.now());
    url.searchParams.append('token', token);
    url.searchParams.append('projectId', 'n7hnngimnxalqi2ih8euj59z3upscog1');

    fetch(url, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'x-access-token': token
        }
    })
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();
        })
        .then(data => {
            console.log('模块树数据:', data);
            // 处理模块树数据
        })
        .catch(error => {
            console.error('获取模块树失败:', error);
        });
};
const getOapi = () => {
    let data = { projectId: 'n7hnngimnxalqi2ih8euj59z3upscog1' }
    Client.post("http://10.0.108.4:3000/hanson-lcdp/oapi/ncstest/test/body1", data, (data) => {
        // setState((state)=>({...state,res:data}))
        console.log(data);
        console.log("ok");
        console.log(data);
    }, (e) => {
        console.log("error");
        console.log(e);
    })
}
const getAudit1DocList = () => {
    let user_id = login_res.data.userInfo.id
    let data = {
        "interfaceId": "oapi:477412c828f64074b06f78a3191ff27b",
        "reqCode": "",
        "pageData": {
            "pageSize": 20,
            "current": 1
        },
        "userId": user_id
    }
    Client.post("http://10.0.108.4:3000/hanson-lcdp/oapi/testFlow/audit1/getAudit1DocList", data, (data) => {
        // setState((state)=>({...state,res:data}))
        console.log(data);
        console.log("ok");
        console.log(data);
    }, (e) => {
        console.log("error");
        console.log(e);
    })
}

Client.post("http://10.0.108.4:3000/hanson-lcdp/sys/login", data, (data) => {
    // setState((state)=>({...state,login_data:data}))
    console.log("ok");
    console.log(data);
    login_res = data;
    // getMethod();
    // getModuleTree()
    // getOapi();
    if (login_res.code == '00000') {
        // getAudit1DocList();
        getModuleTree0()
    }
    else {
        console.log("login failed")
    }
    // console.log("getCategoryList=========")
    // Client.get("http://10.0.108.4:3000/hanson-lcdp/category/getCategoryList",{_t:1691388099,type:2},(data)=>{
    //     console.log(data);
    // },(err)=>{
    //     console.log(err);
    // });

}, (e) => {
    console.log("error");
    console.log(e);
})
